<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>嵌套路由</title>
    <script src="/js/js/vue.js"></script>
    <script src="/js/js/vue-router_3.0.2.js"></script>
    <style>
        .router-link-active{
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div id="app">
        <router-link to="/main">主页</router-link>
        <router-link to="/reg">注册</router-link>
        <router-view></router-view>
    </div>
    <script>

        var main = {
            template:`<h1>主页内容</h1>`
        }

        var reg = {
            template:`<div><h1>注册</h1>
            <router-link to="/chengxu">小程序</router-link>
            <router-link to="/youxi">小游戏</router-link>
            <router-view></router-view></div>
            `
        }
        var chengxu={
            template:`<h1>程序</h1>`
        }
        var youxi={
            template:`<h1>游戏</h1>`
        }
        // 嵌套路由配置
        var router = new VueRouter({
            routes:[
                { path: '/', redirect: "/main" },
                { path: '/main', component: main },
                { 
                    path: '/reg', 
                    component: reg ,
                    children:[
                    {path: '/chengxu', component: chengxu},
                    {path: '/youxi', component: youxi},
                    ]
                }
            ]
        })
        
        var vm = new Vue({
            el:'#app',
            data:{},
            router: router // 挂载路由
        })
       
    </script>
</body>
</html>
